﻿using System;

namespace demo1
{
    class Program
    {
        static void Main(string[] args)
        {
            //字符串，字符串连接
            string
                fname,
                lname;
            fname = "Rowan";
            lname = "Atkinson";

            string fullname = fname + lname;
            Console.WriteLine("Full Name: {0}", fullname);

            //通过使用 string 构造函数
            char[] letters = { 'H', 'e', 'l', 'l', 'o' };
            string greetings = new string(letters);
            Console.WriteLine("Greetings: {0}", greetings);

            //方法返回字符串
            string[] sarray = { "Hello", "From", "Tutorials", "Point" };
            string message = String.Join(" ", sarray);
            Console.WriteLine("Message: {0}", message);

            //用于转化值的格式化方法
            DateTime waiting = new DateTime(2012, 10, 10, 17, 58, 1);
            string chat =
                String.Format("Message sent at {0:t} on {0:D}", waiting);
            Console.WriteLine("Message: {0}", chat);

            // Length 获取在当前的 String 对象中获取字符数。
            string a = "'hkshafjkhdjfkdhskafj'";
            Console.WriteLine("{0}", a.Length);

            // 比较字符串
            string str1 = "abcdef";
            string str2 = "abcdef2";
            if (String.Compare(str1, str2) == 0)
            {
                Console.WriteLine("str1 与 str2 is eauql");
            }
            else
            {
                Console.WriteLine("str1 与 str2 is not eauql");
            }

            // 字符串包含字符串
            string str4 = "This is test";
            if (str4.Contains("test"))
            {
                Console.WriteLine("The sequence 'test' was found.");
            }

            // 获取子字符串
            string str3 = "Last night I dreamt of San Pedro";
            Console.WriteLine (str3);
            string substr = str3.Substring(23);
            Console.WriteLine (substr);

            // 连接字符串
            string[] starray =
                new string[] {
                    "Down the way nights are dark",
                    "And the sun shines daily on the mountain top",
                    "I took a trip on a sailing ship",
                    "And when I reached Jamaica",
                    "I made a stop"
                };
            string str5 = String.Join("\n", starray);
            Console.WriteLine (str5);
            Console.ReadKey();
        }
    }
}
